
/**
 * Created by Administrator on 2017/8/13 0013.
 */
$(function () {
   $(document).on('click', '.i_want_to_participate', function () {
       var _this = $(this);
       $.confirm('确定要申请参加本次活动？', function () {
           $.ajax({
               type : 'post',
               url : SCOPE.participate_activity_url,
               data : {
                   id : _this.data('id'),
               },
               dataType : 'json',
               success : function (msg) {
                   if (msg.code == 200) {
                       $.toptip('申请成功', 'success');
                       if (SCOPE.activity_page_type == 'nearby') {
                           get_activity_info(_this.data('id'));
                       } else  {
                           window.location.reload();
                       }
                   } else {
                       $.toptip(msg.msg, 'error');
                   }
               }
           });
       }, function () {

       });
   });

    /**
     * 签到
     */
    $(document).on('click', '.activity_registration', function () {
        var _this = $(this);
        $.ajax({
            type : 'post',
            url : SCOPE.activity_registration_url,
            data : {
                id : _this.data('id'),
            },
            dataType : 'json',
            success : function (msg) {
                if (msg.code == 200) {
                    $.toptip('签到成功', 'success');
                    if (SCOPE.activity_page_type == 'nearby') {
                        get_activity_info(_this.data('id'));
                    } else  {
                        window.location.reload();
                    }
                } else {
                    $.toptip(msg.msg, 'error');
                }
            }
        });
        $.get($(this).data('href'), function (msg) {
            if (msg.code == 200) {
                $.toptip('签到成功', 'success');
                setTimeout(function () {
                    window.location.reload();
                }, 888);
            } else {
                $.toptip(msg.msg);
            }
        }, 'json');
    });

    $(document).on('click', '.quit_activity', function () {
        var _this = $(this);
        $.confirm('确定要退出本次活动？', function () {
            $.ajax({
                type : 'post',
                url : SCOPE.quit_activity_url,
                data : {
                    id : _this.data('id'),
                },
                dataType : 'json',
                success : function (msg) {
                    if (msg.code == 200) {
                        $.toptip('退出成功', 'success');
                        if (SCOPE.activity_page_type == 'nearby') {
                            get_activity_info(_this.data('id'));
                        } else  {
                            window.location.reload();
                        }
                    } else {
                        $.toptip(msg.msg, 'error');
                    }
                }
            });
        }, function () {

        });
    });
});